Python Plot windows cannot be closed when working with GUI

by: Ammoun, 7 years ago


have a graphical interface which contains a button called "generate graph" which when clicked generate graphs (plots) with matplotlib. I can generate the plots but I cannot control these windows when the graphical interface is opened : I cannot close, save, zoom, ....

However, when I close the graphical interface, I can have the control over these plots : close, save, zoom, ...

I found in the internet that the problem is caused by the fact that matplotlib windows uses QT and my GUI interface uses also QT.

I have tested solutions proposed but no one works for me. Could you help me ?

For information, here is my code used to generate graphs :

firstPlot = False


        #Plot graph and display it



        if(self.DropDownListDisplaySector2_1.currentIndex() != self.currentSectorPlot2_1):
            self.numFiguresPlot2_1 = self.numFiguresPlot2_1 + 1
            self.currentSectorPlot2_1 = self.DropDownListDisplaySector2_1.currentIndex()
            firstPlot = True


        fig = plt.figure(self.numFiguresPlot2_1)


        fig.canvas.set_window_title(self.DropDownListDisplaySector2_1.currentText())
        plt.hold(True)

        x = np.arange(0, self.stockParam.nTotZones, 1);
        #y = matrix4["Price"].convert_objects(convert_numeric=True)
        y = pd.to_numeric(matrix4["Price"])
        print("Moyenne = ")
        print(y.mean(0))
        #z = (matrix4["Adjust"].convert_objects(convert_numeric=True)*y)/100 + y
        z = pd.to_numeric(matrix4["Adjust"]*y)/100 + y

        if(firstPlot):
            price = plt.plot(x, y, label = ("Price"))
        shadowPrice = plt.plot(x, z, label = ("Price + adjust for iteration "+self.DropDownListDisplayIter2_1.currentText()))

        plt.legend()


        plt.show(block=False) #method 3
        plt.draw()




You must be logged in to post. Please login or register an account.